/**
 * Created by Administrator on 2016/12/13.
 */
/*  新增主账号  子账号  */
$("#newBtn").on("click", function () {
    var newMes = {};
    $(".new-page [data-name]").each(function (i, element) {
        if ($(element).attr('data-name') == 'isValid') {
            newMes.isValid = $("#switch").text() == '已开启' ? "1" : "0";
        } else if ($(element).attr('data-name') == 'accountType') {
            newMes.accountType = $(".navL p").html() == '新增主账号' ? "1" : "0";
        } else {
            newMes[$(element).attr('data-name')] = $(element).val();
        }

    });
    var url = "http://192.168.59.23:8082/console/addUserAccountInfo";
    $.ajax({
        type: "get",
        url: url,
        data: newMes
    });

    console.log(newMes)
});
/*  启用状态  */
$(function () {
    var i = 0;
    $(".switchs").on("click", function () {
        i++;
        if (i % 2 == 1) {
            $("#switch").text("已关闭");
        } else {
            $("#switch").text("已开启");
        }
    })
});

/*  新增银行对公账号  个人账号  */
$("#bankBtn").on("click", function () {
    var bankMes = {};
    $(".new-page [data-name]").each(function (i, element) {
        if ($(element).attr('data-name') == 'isPublic') {
            bankMes.isPublic = $(".navL p").html() == '新增银行卡对公账号' ? "0" : "1";
        } else {
            bankMes[$(element).attr('data-name')] = $(element).val();
        }
        !$(".bnak")
    });

    console.log(bankMes)
    var url = "http://192.168.59.23:8082/console/addBankCardInfo";
    $.ajax({
        type: "get",
        url: url,
        data: bankMes
    });

});
/* 失去焦点事件 */
function lose() {
    $(".bankLook input").each(function (i, ipt) {
        $(ipt).blur(function () {
            !$(ipt).val() ?
                $(".bankLook span").eq(i).show() :
                $(".bankLook span").eq(i).hide();
        });
    });
}
lose();

/*  账号详情 */

var str = location.search;
str = str.slice(1).split('&');
json = {}
console.log(str);
for (var i = 0; i < str.length; i++) {
    var a = str[i].split('=');
    console.log(a);
    json[a[0]] = a[1];
}
console.log(json);

$(".accLook [data-name]").each(function (i, element) {

    $(this).text(decodeURI(json[$(element).attr('data-name')]));
});

$(".accEdit [data-name]").each(function (i, element) {

    if ($(element).attr('data-name') == 'isValid') {
        console.log(decodeURI(json.isValid));
        if(decodeURI(json.isValid)=='已开启'){
            $(this).text(decodeURI(json[$(element).attr('data-name')]));
        }
    }
});